#include <iostream>

// 定义链表节点结构体
struct ListNode
{
    int data;
    ListNode *next;
};

// 定义仿函数类
class PrintFunctor
{
public:
    void operator()(ListNode *head)
    {
        ListNode *current = head;
        while (current != nullptr)
        {
            std::cout << current->data << " -> ";
            current = current->next;
        }
        std::cout << "NULL" << std::endl;
    }
};

int main()
{
    // 创建链表
    ListNode *head = new ListNode{1, new ListNode{2, new ListNode{3, nullptr}}};

    // 使用仿函数打印链表
    PrintFunctor printFunctor;
    printFunctor(head);

    // 释放链表内存
    delete head->next->next;
    delete head->next;
    delete head;

    return 0;
}
